package panel.help
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	import assists.HtmlText;
	import assists.TextFieldUtils;
	
	import panel.viewSpots.navigation.ScrollTxtHor;
	
	public class TrafficCarItem extends Sprite
	{
		private var _stage:Stage;
		
		private var _name:TextField = new TextField();
		private var _startPos:TextField = new TextField();
		private var _endPos:TextField = new TextField();
		private var _startTime:TextField = new TextField();
		private var _endTime:TextField = new TextField();
		public function TrafficCarItem(stage:Stage)
		{
			_stage = stage;
			
			_name.mouseEnabled = false;
			_name.width = stage.stageWidth * 0.2;
			_name.wordWrap = true;
			_name.multiline = true;
			_name.autoSize = "left";
			
			_startPos.mouseEnabled = false;
			_startPos.autoSize = "left";
			
			_endPos.mouseEnabled = false;
			_endPos.autoSize = "left";
			
			_startTime.mouseEnabled = false;
			_startTime.width = stage.stageWidth * 0.42;
			_startTime.wordWrap = true;
			_startTime.multiline = true;
			_startTime.autoSize = "left";
			
			_endTime.mouseEnabled = false;
			_endTime.width = stage.stageWidth * 0.42;
			_endTime.wordWrap = true;
			_endTime.multiline = true;
			_endTime.autoSize = "left";
			
//			_startTime.showWid = _stage.stageWidth * 0.42;
//			_endTime.showWid = _stage.stageWidth * 0.42;
		}
		
		public function show(data:Object):void
		{
			TextFieldUtils.setHtmlText(_name,HtmlText.format(data.name,0xffffff));
			TextFieldUtils.setHtmlText(_startPos,HtmlText.format(data.start,0xffffff));
			TextFieldUtils.setHtmlText(_endPos,HtmlText.format(data.end,0xffffff));
			if(data.endTime == "")
			{
				TextFieldUtils.setHtmlText(_endTime,HtmlText.format(data.startTime,0xffffff,14));
				
			}else
			{
				TextFieldUtils.setHtmlText(_endTime,HtmlText.format(data.endTime,0xffffff,14));
			}
			TextFieldUtils.setHtmlText(_startTime,HtmlText.format(data.startTime,0xffffff,14));
			
			layout();
		}
		
		private function layout():void
		{
			var startX:int = _stage.stageWidth * 0.02;
			var endX:int = _stage.stageWidth * 0.98;
			var endY:int = _startPos.height * 4;
			
			this.graphics.clear();
			this.graphics.lineStyle(1);
			this.graphics.moveTo(startX,0);
			this.graphics.lineTo(startX,endY);
			this.graphics.lineTo(endX,endY);
			this.graphics.lineTo(endX,0);
			
			this.graphics.moveTo(_stage.stageWidth * 0.32,0);
			this.graphics.lineTo(_stage.stageWidth * 0.32,endY);
			
			this.graphics.moveTo( _stage.stageWidth * 0.52,0);
			this.graphics.lineTo(_stage.stageWidth * 0.52,endY);
			
			this.graphics.moveTo(_stage.stageWidth * 0.32,endY * 0.5);
			this.graphics.lineTo(endX,endY * 0.5);
			this.graphics.endFill();
			
			_name.x = startX + _name.width * 0.25;
			_name.y = (endY - _name.height) * 0.5;
			
			_startPos.x = _stage.stageWidth * 0.32 + (_stage.stageWidth * 0.2 - _startPos.width) * 0.5;
			_startPos.y = _startPos.height * 0.5;
			
			_endPos.x = _stage.stageWidth * 0.32 + (_stage.stageWidth * 0.2 - _endPos.width) * 0.5;
			_endPos.y = _startPos.height * 2.5;
			
			_startTime.x = startX + _stage.stageWidth * 0.51;
			_startTime.y = _startPos.y + (_startPos.height  - _startTime.height) * 0.5;
			
			_endTime.x = _startTime.x;
			_endTime.y = _endPos.y + (_endPos.height  - _endTime.height) * 0.5;
			
			this.addChild(_name);
			this.addChild(_startPos);
			this.addChild(_endPos);
			this.addChild(_startTime);
			this.addChild(_endTime);
		}		
		
	}
}